using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using System.Data;
using DTO;

namespace DAO
{
    public class BoPhanDAO
    {
        public List<BoPhanDTO > laydanhsachbophan_DAO() // tu csdl tra ve list DTO 
        {
            List<BoPhanDTO> list = new List<BoPhanDTO>(); // 
            string sql = "select * from BoPhan";
            DataTable dt = DataProvider.ExcuteQuery(sql);
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow dr = dt.Rows[i];

                    int mabophan = int.Parse(dr["MaBoPhan"].ToString());
                    string tenbophan = dr["TenBoPhan"].ToString();

                    BoPhanDTO  bp = new BoPhanDTO ();

                    bp.Mabophan = mabophan;
                    bp.Tenbophan = tenbophan;

                    list.Add(bp);
                }
            }
            return list;

        }
        public BoPhanDTO  laytentheoma_DAO(int mabophan)
        {
            BoPhanDTO  bp = new BoPhanDTO ();
            string sql = "select * from BoPhan where MaBoPhan = " + mabophan;
            DataTable dt = DataProvider.ExcuteQuery(sql);
            DataRow dr = dt.Rows[0];
            string tenbophan = dr["TenBoPhan"].ToString();
            bp.Tenbophan  = tenbophan;
            return bp;
        }
    }
}
